|
DHTMLX Documentation |
grid._in_header_stat_count=function(tag,index,c){ //shortcut for statistics counterThere are some differences between default shortcats and statistics counters:
var calck=function(){ // define the function which will be used for calculations
return this.getRowsNum();
}
this._stat_in_header(tag,calck,index,c); //call default statistics handler processor
}
grid._in_header_stat_summ=function(tag,index,c){ // shortcut for statistics counterThis snippet uses a slightly more complex approach: each time when any changes in the grid occur and the calculation function is called, the code iterates through all the rows and calculates the sum of value in the related cells.
var calck=function(){ // define the function which will be used for calculations
var summ=0; // set initial counter value
this.forEachRow(function(id){ // for each row
summ+=this.cells(id,index).getValue(); // add row_value
})
return summ;
}
this._stat_in_header(tag,calck,index,c); //call default statistics handler processor
}
grid._in_header_stat_deviation=function(tag,index,c){ //the marker for statistics counterAs you can see the changes are minimal - we just added some math to the calculations.
var calck=function(){ // define the function which will be used for calculations
var summ=0; //set initial
this.forEachRow(function(id){
summ+=Math.pow(this.cells(id,index).getValue,2);
})
return summ/this.getRowsCount();
}
this._stat_in_header(tag,calck,index,c); //call the default statistics handler processor
}
return Math.round(summ/this.getRowsCount()*100)/100;This will round the value to 2 digits in a simple and fast way.
return this._aplNF(summ,index);
The confusing _aplNF stands for the name of the inner grid function which is used for edn excells and can be reused to apply the same formating to autocalculated values.
As with the normal shortcuts, statistics counters can be defined on prototype level, so all the instances of the grid will be affected:
dhtmlXGridObject.prototype._in_header_SOME=function(tag,index){
....
}
grid._in_header_stat_count=function(tag,index,c){ //shortcut for statistics counterAnd somewhere on the page you have:
var calck=function(){ // define the function which will be used for calculations
return this.getRowsNum();
}
this._stat_in_header(tag,calck,index,c); //call the default statistics handler processor
}
there are <span id="grid_count"></span> rows in my gridYou can link stat_count to the span element in the following way:
grid._in_header_stat_count(document.getElementById('grid_count'),1);After such command the content of grid_count element will be always equal to the number of rows in the grid.